let num:number=440;
console.log(intToRoman(num));

function intToRoman(num: number): string {
    let result:string=""
    result+=step1000(num)
    return result;
};
function step1000(num:number):string{
    let result:string=""
    result+="M".repeat(Math.floor(num/1000));
    num=num%1000;
    if(num>=900)
        result+=step900(num)//900<=num<1000
    else
        result+=step500(num)//0<=num<900
    return result;
}
function step900(num:number):string{
    let result:string="CM"
    num=num-900;//0~100
    if(num>=90)
        result=result+step90(num); // 90<=num<100
    else
        result=result+step50(num); // 0<=num<90
    return result;
}
function step500(num:number):string{
    let result:string="";
    if(num>=500)
        result="D";
    num=num%500;
    if(num>=400)
        result+=step400(num);
    else
        result+=step100(num);//0 ~ 300
    return result;
}
function step400(num:number):string{
    let result:string="CD"
    num=num-400;
    if(num>=90)
        result=result+step90(num)
    else
        result=result+step50(num)
    return result;
}
function step100(num:number):string{
    let result:string="C"
    result="C".repeat(Math.floor(num/100));
    num=num%100;//0~100
    if(num>=90)
        result=result+step90(num)// 90~100
    else
        result=result+step50(num)// 0~90
    return result;
}
function step90(num:number):string{
    let result:string="XC"
    num=num-90;//  >= 10
    if(num===9)
        result=result+"IX"
    else
        result=result+step5(num) // 0<=num<9
    return result;
}
function step50(num:number):string{
    let result:string=""
    if(num>=50)
        result="L"
    num=num%50;// 0~50
    if(num>=40)
        result=result+step40(num)
    else
        result=result+step10(num);
    return result;
}
function step40(num:number):string{
    let result:string="XL"
    num=num-40;
    if(num===9)
        result=result+"IX"
    else
        result=result+step5(num);
    return result;
}
function step10(num:number):string{
    let result:string=""
    result="X".repeat(Math.floor(num/10))
    num=num%10;
    if(num===9)
        result=result+"IX"
    else
        result=result+step5(num)
    return result;
}
function step5(num:number):string{
    let result:string=""
    if(num>=5)
        result="V"
    num=num%5;
    if(num===4)
        result=result+"IV"
    else
        result=result+step1(num)
    return result;
}
function step1(num:number):string{
    let result:string=""
    result="I".repeat(Math.floor(num/1))
    return result;
}